package cn.heapstack.util;

/**
 *
 * @author ehaojii
 * 
 * @see  {@link Option#shortOptStr},
 *  {@link Option#longOptStr},
 *  {@link  Option#optValue},
 *  {@link  Option#isRequired},
 *  {@link  Option#isSpecified},
 *	{@link  Option#mustSpecifyValue}
 *  
 */
public class Option
{
    public boolean isMustSpecifyValue() {
        return mustSpecifyValue;
    }
    public void setMustSpecifyValue(boolean mustSpecifyValue) {
        this.mustSpecifyValue = mustSpecifyValue;
    }
    public String getShortOptStr() {
        return shortOptStr;
    }
    public void setShortOptStr(String shortOptStr) {
        this.shortOptStr = shortOptStr;
    }
    public String getLongOptStr() {
        return longOptStr;
    }
    public void setLongOptStr(String longOptStr) {
        this.longOptStr = longOptStr;
    }
    public String getHelpMessage() {
        return helpMessage;
    }
    public void setHelpMessage(String helpMessage) {
        this.helpMessage = helpMessage;
    }
    public String getOptValue() {
        return optValue;
    }
    public void setOptValue(String optValue) {
        this.optValue = optValue;
    }
    public boolean isRequired() {
        return isRequired;
    }
    public void setRequired(boolean isRequired) {
        this.isRequired = isRequired;
    }
    public boolean isSpecified()
    {
        return isSpecified;
    }
    public void setSpecified(boolean isSpecified)
    {
        this.isSpecified = isSpecified;
    }

    /**
     * The constructor of the option
     * 
     * @param shortOptStr
     *          - normally is one character
     * @param longOptStr
     *          - normally a word which explains the shortOptStr
     * @param helpMessage
     *          - the message that used to explain the option means what
     * @param isRequired
     *          - whether this option is required
     * @param mustSpecifyValue
     *          - whether this option's value is required
     */
    public Option(String shortOptStr, String longOptStr, String helpMessage,
            boolean isRequired, boolean mustSpecifyValue) {
        super();
        this.shortOptStr = shortOptStr;
        this.longOptStr = longOptStr;
        this.helpMessage = helpMessage;
        this.isRequired = isRequired;
        this.mustSpecifyValue = mustSpecifyValue;
        this.isSpecified = false;
    }
    
    @Override
    public String toString()
    {
        StringBuilder sb = new StringBuilder();
        sb.append("[shortOptStr : ");
        sb.append(shortOptStr);
        sb.append("] \t[longoptStr : ");
        sb.append(longOptStr);
        sb.append("] \t[isRequired : ");
        sb.append(isRequired);
        sb.append("] \t[isSpecified : ");
        sb.append(isSpecified);
        sb.append("] \t[mustSpecifyValue : ");
        sb.append(mustSpecifyValue);
        sb.append("] \t[optValue : ");
        sb.append(optValue);
        sb.append("] \t[helpMessage : ");
        sb.append(helpMessage);
        sb.append("]");
        
        return sb.toString();
    }
    
    /**
     * example: -t is a short option, -TIME is a long option string
	 * <br><b>you can either specify -t or -TIME</b>
     */
    private String shortOptStr;
    
    /**
     * example: -t is a short option, -TIME is a long option string
	 * <br><b>you can either specify -t or -TIME</b>
     */
    private String longOptStr;
    
    /**
     * The message to explain the option, to help user 
     */
    private String helpMessage;
    
    /**
     * example: -TIME 20090101
	 * <br><b>you can specify the option's value, 
	 * and you must specify the value if this.mustSpecifyValue is true</b>
     */
    private String optValue;
    
    /**
     * If this field's value is true, then you must specify the shortOptStr or longOptStr
     * @see {@link Option#shortOptStr}, {@link Option#longOptStr} 
     */
    private boolean isRequired;
    
    /**
     * If this field's value is true, then you must specify the optValue
     * @see {@link Option#optValue} 
     */
    private boolean mustSpecifyValue;
    
    /**
     * The flag will be set true when parse command line args 
     * and find there is such an Option (shortOptStr or longOptStr is specified)
     */
    private boolean isSpecified;
   
}
